
export default class anjian extends Laya.Script {
    // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
        /** @prop {name:player, tips:"布尔类型示例", type:Node, default:null}*/
        player=null;
    zuo=null;
    you=null;
    shang=null;
    rig=null;
    speed=10;
    ischu=true;
    isgamerover=false;
    constructor() { super(); }
    onAwake(){
        
        this.rig=this.player.getComponent(Laya.RigidBody);
        this.zuo=this.owner.getChildByName("zuo");
        this.you=this.owner.getChildByName("you");
        this.shang=this.owner.getChildByName("shang");
        Laya.stage.on("gamerover",this,function(){this.isgamerover=true})
        Laya.stage.on("start",this,function(){this.isgamerover=false})
        if(!this.isgamerover){
        this.zuo.on(Laya.Event.MOUSE_DOWN,this,this.Zuo);
        this.you.on(Laya.Event.MOUSE_DOWN,this,this.You);
        this.shang.on(Laya.Event.CLICK,this,this.Shang);  
        }
        this.zuo.on(Laya.Event.MOUSE_UP,this,this.mouseUp);
        this.you.on(Laya.Event.MOUSE_UP,this,this.mouseUp);
        this.shang.on(Laya.Event.MOUSE_UP,this,this.mouseUp);
        Laya.stage.on("food",this,function(){this.speed=20;
        this.shang.visible=true;})
        Laya.stage.on("chu",this,function(){this.ischu=true})
        Laya.stage.on("li",this,function(){this.ischu=false})
        
    }
    Zuo(){
        this.rig.linearVelocity={x:-this.speed,y:this.rig.linearVelocity.y}
    }
    You(){
        this.rig.linearVelocity={x:this.speed,y:this.rig.linearVelocity.y}
    }
    Shang(){
        if(this.player.y<750)return; 
        if(this.ischu)( this.rig.linearVelocity={x:this.rig.linearVelocity.x,y:-15})
       
    }
    mouseUp(){
       
        this.rig.linearVelocity={x:0,y:0}
    }
}